﻿using System;

namespace SmartHRMS.Infrastructure
{
   public class Kit
    {


        /// <summary>
        /// Return true when argument is null or empty (after trimmed).
        /// </summary>
        /// <param name="arg">Input object</param>
        /// <returns>True when argument is null or empty (after trimmed).</returns>
        public static bool IsEmpty(object arg)
        {
            if (arg == null)
            {
                return true;
            }

            return arg.ToString().Trim().Length == 0;
        }

        /// <summary>
        /// If arguement is null, it will throw ArgumentNullException
        /// </summary>
        /// <param name="arg">Input argument for checking.</param>
        /// <param name="argumentName">Argument name in thrown exception.</param>
        public static void NotNull(object arg, string argumentName)
        {
            if (arg == null)
                throw new ArgumentNullException(argumentName);

            if (arg.ToString().Trim() == "")
            {
                throw new ArgumentNullException(argumentName);
            }
        }

        public static string EncryptPassword(string password)
        {
            string rethash = "";
            try
            {

                System.Security.Cryptography.SHA1 hash = System.Security.Cryptography.SHA1.Create();
                System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
                byte[] combined = encoder.GetBytes(password);
                hash.ComputeHash(combined);
                rethash = Convert.ToBase64String(hash.Hash);
            }
            catch (Exception ex)
            {
                string strerr = "Error in HashCode : " + ex.Message;
            }
            return rethash;
        }

    }
}
